var Relation = require('../relation');
var User = require('../user')
var Card = require('../card')
var Activity = require('../activity');
var initRedisCache = require('../../lib/InitRedisCache');
var Faction = require('../faction');
var fmproxy = require('../factionmember');
var Creditspolicy = require('../creditspolicy');
var FactionMember = require('../../entity').FactionMember;
var activity = require('../../entity').Activity;
var UserE = require('../../entity').User;
var CardE = require('../../entity').Card;



function check(){
    // 检查用户名片数据
    /*User.getAllUsers(function(err, users){
        for(var i in users){
            (function(user){
                if(!user.card){
                    console.log('no card user : '+user._id +' ----------------');
                }else{
                    console.log('User :'+user._id+' is OK~')
                }
                CardE.findOne({userId: user._id}).exec(function(err, card){
                    if(!card){
                        console.log('card is none user: '+user._id+' ----------------');
                    }else{
                        console.log('Card: '+card._id+' is Good~')
                    }
                })
            })(users[i])
        }
    })*/
    // 补充名片数据
    var ids = ['5437b1e26f03d9591e7246a8',
            '5437b66b6f03d9591e72472e',
            '5437d503f2afff41cc32407b',
            '5437b19e6f03d9591e7246a5'];
    for(var i in ids){
        (function(id){
            CardE.findOne({userId: id}).exec(function(err, card){
                UserE.update({_id: id}, {$set: {card: card._id}}, {}, function(err, data){
                    console.log(' user and card ok~ '+data)
                });
            })
            /*UserE.findOne({_id: id}).exec(function(err, user){
                Card.newAndSave(user, {}, function(err, card){
                    console.log(user._id+' create Card Ok ~');
                })
            })*/
        })(ids[i])
    }
}

check();